package warmup;

import java.util.Objects;

public class Student implements Comparable<Student> {
    private String studentId;
    private String name;
    private int age;

    // 构造函数
    public Student(String studentId, String name, int age) {
        this.studentId = studentId;
        this.name = name;
        this.age = age;
    }

    // --- Getter 和 Setter ---

    // studentId 只有 getter（根据要求）
    public String getStudentId() {
        return studentId;
    }

    // name 的 getter 和 setter
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    // age 的 getter 和 setter
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // --- 必须实现的方法 ---

    // 实现 Comparable 接口的 compareTo 方法
    @Override
    public int compareTo(Student other) {
        return this.studentId.compareTo(other.studentId);
    }

    // 重写 toString()
    @Override
    public String toString() {
        return "Student{" +
                "studentId='" + studentId + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    // 重写 equals() - 以 studentId 为判断依据
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(studentId, student.studentId);
    }

    // 重写 hashCode() - 以 studentId 为判断依据
    @Override
    public int hashCode() {
        return Objects.hash(studentId);
    }
}